package com.quan.pm.service.impl;

import com.quan.commons.core.MyBaseServiceImpl;
import com.quan.commons.utils.PageUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import lombok.extern.slf4j.Slf4j;

import java.util.List;
import java.util.stream.Collectors;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;

import com.quan.pm.commons.vo.PmProjectDevEmpVo;
import com.quan.pm.entity.PmProjectDevEmp;
import com.quan.pm.mapper.PmProjectDevEmpMapper;
import com.quan.pm.service.PmProjectDevEmpService;


@Slf4j
@Service
public class PmProjectDevEmpServiceImpl extends MyBaseServiceImpl<PmProjectDevEmpMapper, PmProjectDevEmp> implements PmProjectDevEmpService {

    @Autowired
    private PmProjectDevEmpMapper mapper;

    @Override
    public List<PmProjectDevEmpVo> queryList(PageUtils pageUtils, PmProjectDevEmpVo vo) {
        QueryWrapper<PmProjectDevEmp> queryWrapper = new QueryWrapper<PmProjectDevEmp>(vo);

        List<PmProjectDevEmp> list = super.list(pageUtils, queryWrapper);
        List<PmProjectDevEmpVo> collect = list.stream().map(item -> {
                PmProjectDevEmpVo bean = new PmProjectDevEmpVo();
            BeanUtils.copyProperties(item, bean);
            return bean;
        }).collect(Collectors.toList());

        return collect;
    }

    @Override
    public PageUtils queryPage(PageUtils pageUtils, PmProjectDevEmpVo vo) {
        QueryWrapper<PmProjectDevEmp> queryWrapper = new QueryWrapper<PmProjectDevEmp>(vo);

        if (StringUtils.isNotBlank(vo.getKeyword())) {
            queryWrapper.and(w -> {
                w.like("name", vo.getKeyword());
            });
        }

        final IPage<PmProjectDevEmp> page = super.selectPage(pageUtils, queryWrapper);

        PageUtils ps = new PageUtils(page);

        final List<PmProjectDevEmp> records = page.getRecords();

        final List<PmProjectDevEmp> collect = records.stream().map((item) -> {
                PmProjectDevEmpVo bean = new PmProjectDevEmpVo();
            BeanUtils.copyProperties(item, bean);
            return bean;
        }).collect(Collectors.toList());

        ps.setRecords(collect);
        return ps;
    }
}